﻿<%@ Control Language="C#" ClassName="PaymentTransactions" Inherits="Dimok.Web.UI.TableControl" %>
<script runat="server">
	protected override void OnInit(EventArgs e) {
		base.OnInit(e);
		Page.LoadComplete += new EventHandler(Page_LoadComplete);
	}

	void Page_LoadComplete(object sender, EventArgs e) {
		if(IsPostBack)
			GridViewEx.DataBind();
	}

	public int LoanID { get {
		var i = 0;
		int.TryParse(Lib.GetProperty(Parent, "LoanID")+"", out i);
		return i;
	} }
	public int PaymentID { get { return (int)Lib.GetProperty(Parent, "PaymentID"); } }
</script>
<asp:UpdatePanel ID="upPaymentTransactions" UpdateMode="Always" runat="server">
	<ContentTemplate>
<DS:FunctionDataSource ID="dsPaymentTransactions" SelectViewName="v_PaymentTransaction WHERE ISNULL(@Param1,0) IN (0,PaymentID) AND LoanID = @Param2" InsertViewName="t_PaymentTransaction" UpdateViewName="t_PaymentTransaction" runat="server">
	<SelectParameters><asp:ControlParameter PropertyName="Page.PaymentID" Name="Param1" Type="Int32" /></SelectParameters>
	<SelectParameters><asp:ControlParameter PropertyName="Page.LoanID" Name="Param2" Type="Int32" /></SelectParameters>
</DS:FunctionDataSource>
<UI:GridViewEx DataSourceID="dsPaymentTransactions" DataKeyNames="ID" AllowEdit="true" 
								ShowDelete="false" AllowSorting="true" ShowFooter="true" ShowSearch="true" AutoGenerateColumns="false" runat="server">
	<Columns>
	<asp:TemplateField HeaderText="PaymentID" SortExpression="PaymentID">
		<ItemTemplate><%#Eval("PaymentID")%></ItemTemplate>
		<FooterTemplate>
			<DS:FunctionDataSource ID="dsPayments" runat="server" SelectViewName="t_Payment WHERE LoanID=@Param1 AND ISNULL(@Param2,0) IN (ID)">
			<SelectParameters>
			<asp:ControlParameter ControlID="dsPayments" PropertyName="Page.LoanID" Name="Param1" Type="Object" ConvertEmptyStringToNull="true" />
			<asp:ControlParameter ControlID="dsPayments" PropertyName="Page.PaymentID" Name="Param2" Type="Object" ConvertEmptyStringToNull="true" />
			</SelectParameters>
			</DS:FunctionDataSource>
			<UI:DropDownListEx ID="PaymentID" SelectedValue='<%#Bind("ID") %>' DataSourceID="dsPayments" DataTextField="ID" DataValueField="ID" runat="server"/>
		</FooterTemplate>
	</asp:TemplateField>
	<asp:TemplateField HeaderText="Amount" SortExpression="Amount" >
		<ItemTemplate><%#Eval("Amount")%></ItemTemplate>
		<EditItemTemplate><asp:TextBox ID="txtAmount" Text='<%#Bind("Amount")%>' runat="server" /></EditItemTemplate>
		<FooterTemplate><asp:TextBox ID="Amount" Text='<%#Bind("Amount")%>' runat="server" /></FooterTemplate>
	</asp:TemplateField>
	<asp:TemplateField HeaderText="TypeName" SortExpression="TypeName">
		<ItemTemplate><%#Eval("TypeName")%></ItemTemplate>
		<EditItemTemplate>
			<asp:DropDownList ID="selTypeID" SelectedValue='<%#Bind("TypeID") %>' DataSourceID="dsTypes" DataTextField="Name" DataValueField="ID" runat="server"/>
		</EditItemTemplate>
		<FooterTemplate>
			<asp:DropDownList ID="TypeID" SelectedValue='<%#Bind("TypeID") %>' DataSourceID="dsTypes" DataTextField="Name" DataValueField="ID" runat="server"/>
		</FooterTemplate>
	</asp:TemplateField>
	<asp:BoundField DataField="TypeID" HeaderText="TypeID" SortExpression="TypeID" />
	</Columns>
</UI:GridViewEx>
<DS:TableDataSource ID="dsTypes" SelectViewName="ts_PaymentTransactionType" runat="server"/>
</ContentTemplate>
</asp:UpdatePanel>
